<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        // 把数组中的每个值 * 2

        var arr = [1, 2, 3];
        var arr2 = [];
        for (var i = 0; i < arr.length; i++) {
            var v = arr[i] * 2;
            arr2.push(v);
        }
        console.log(arr2);



        // 把数组的每个值乘以3



        // function myMap(arr, n) {
        //     var arr2 = [];
        //     for (var i = 0; i < arr.length; i++) {
        //         var v = arr[i] * n;
        //         arr2.push(v);
        //     }
        //     console.log(arr2);
        //     return arr2
        // }


        // var arr3 = myMap([1, 2, 3], 4);
        // console.log(arr3);





        // 把数组的每个值+1

        function myMap(arr, fn) {
            var arr2 = [];
            for (var i = 0; i < arr.length; i++) {
                // var v = arr[i] * n;
                var v = fn(arr[i]);
                arr2.push(v);
            }
            // console.log(arr2);
            return arr2
        }


        var res = myMap([1, 2, 3], function (v) {
            return v * 2
        })

        console.log(res);




    </script>

</body>

</html>